import 'package:flutter/material.dart';
import 'package:x3_component_core/components/selector_components/selector_template/bottom_sheet_head.dart';

/// 默认单选模板
class BaseDefaultBottomSheetTemplate extends StatefulWidget {
  /// 弹出框的提示信息
  final String hit;

  final Widget child;

  /// 弹出框的高度  MediaQuery.of(context).size.height * 0.7
  final double height;

  /// 弹出框的底部组件
  final Widget footerWidget;

  /// 是否隐藏头部组件
  final bool hiddenHeaderWidget;

  /// 内容内边距
  final EdgeInsets contentPadding;

  /// 构造函数
  const BaseDefaultBottomSheetTemplate({Key key, this.hit, this.child, this.footerWidget, this.height, this.hiddenHeaderWidget = false, this.contentPadding = const EdgeInsets.only(left: 16, right: 16, bottom: 8)}) : super(key: key);

  @override
  _BaseDefaultBottomSheetTemplateState createState() => _BaseDefaultBottomSheetTemplateState();
}

class _BaseDefaultBottomSheetTemplateState extends State<BaseDefaultBottomSheetTemplate> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(child: Container(child: _buildSheetWidget(), height: widget.height));
  }

  Widget _buildSheetWidget() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        widget.hiddenHeaderWidget == true ? SizedBox() : _buildSheetHeaderWidget(),
        Expanded(child: _buildSheetContentWidget()),
      ],
    );
  }

  Widget _buildSheetHeaderWidget() {
    EdgeInsets padding = EdgeInsets.only(left: 16.0, right: 16.0);
    return Container(color: Colors.white, padding: padding, child: BottomSheetHead(hit: widget.hit));
  }

  Widget _buildSheetContentWidget() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Expanded(child: widget.child ?? SizedBox()),
        widget.footerWidget ?? SizedBox(),
      ],
    );
  }
}
